<template>
  <div>
    <el-table :data="list" style="width: 100%">
      <el-table-column prop="name" label="角色"> </el-table-column>
      <el-table-column prop="role" label="权限"> </el-table-column>
      <el-table-column prop="role" label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button v-if="add" @click="addRole(scope.row)" type="text" size="small"
            >添加</el-button
          >
          <el-button v-if="remove" @click="removeRole(scope.row)" type="text" size="small"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import API from "@/api";

export default {
  props: {
    add: {
      type:Boolean,default:true
    },
    remove: {
      type:Boolean,default:true
    }
  },
  data() {
    return {
      list: [],
    };
  },
  created() {
    API.roles
      .list()
      .then((res) => {
        console.log("获取角色成功");
        console.log(res);

        let { data } = res;
        this.list = [];
        this.list = data.list;
      })
      .catch((err) => {
        console.log("获取角色失败");
        console.log(err);
      });
  },
  methods: {
    addRole(e) {
      this.$emit("add", e);
    },
    removeRole(e) {
      this.$emit("remove", e);
    },
  },
};
</script>

<style scoped>
.role-li {
  flex: 1;
  height: 55px;
  line-height: 55px;
  background: #c3c3c3;
}
</style>
